<template>
  <view class="my-container">
    <!-- 没有 token 显示登录 -->
    <my-login v-if="!token"></my-login>

    <!-- 有 token 显示用户信息 -->
    <my-userinfo v-else></my-userinfo>
  </view>
</template>

<script>
import badge from '@/mixins/badge'
import MyLogin from '@/components/my-login.vue'
import MyUserinfo from '@/components/my-userinfo.vue'
import { mapState } from 'vuex'

export default {
  mixins: [badge],
  components: {
    MyLogin,
    MyUserinfo,
  },
  computed: {
    ...mapState('user', ['token']),
  },
  methods: {
    async handleOneLogin() {
      // 获取真实的用户信息
      const [err, res] = await uni.getUserProfile({
        desc: '获取用户基本信息用于登录', // 必须要写
      })

      if (err) return this.$msg('获取用户信息失败！')

      const userInfo = res.userInfo
      // console.log(userInfo)
      this.$store.commit('user/updateUserInfo', userInfo)
    },
  },
}
</script>

<style lang="scss">
page,
.my-container {
  height: 100%;
}
</style>
